package com.soar.recruitment.module.web.bll.web;

import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;

import com.soar.recruitment.module.web.bll.interfaces.OnWebLoadListener;
import com.soar.recruitment.module.web.bll.web.base.BaseWebViewClient;


public class SOARWebViewClient extends BaseWebViewClient {

    private boolean isFailure;

    private OnWebLoadListener mOnWebLoadListener;

    public SOARWebViewClient(OnWebLoadListener onWebLoadListener) {
        this.mOnWebLoadListener = onWebLoadListener;
    }
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        if(mOnWebLoadListener != null) {
            mOnWebLoadListener.showError();
        }
        isFailure = true;
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        if (isFailure) {
            isFailure = false;
            return;
        }
        if(url != null && url.equals("data:text/html,chromewebdata")) {
            if(mOnWebLoadListener != null) {
                mOnWebLoadListener.showError();
            }
            return;
        }
        if(mOnWebLoadListener != null) {
            mOnWebLoadListener.showContent();
        }
    }

    @Override
    public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest
            request) {
        return super.shouldInterceptRequest(view, request);
    }

}
